package web.init;

import java.io.IOException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import DB.DB_connection_pool;
import bean.Credit_parameter;


public class Credit_pram_init extends HttpServlet {
	private static final long serialVersionUID = 1L;

	public void init(ServletConfig config) throws ServletException {
		// TODO Auto-generated method stub
		
String weight_selset = "select * from credit_pram";

			try {
				Connection conn = DB_connection_pool.data_pool.getConnection();
				PreparedStatement ps_select= conn.prepareStatement(weight_selset);
				ResultSet rs = ps_select.executeQuery();
				
				if(rs.next()){
					Credit_parameter.setLogon_1(rs.getInt("logon_1"));
					Credit_parameter.setLogon_2(rs.getInt("logon_2"));
					Credit_parameter.setLogon_3(rs.getInt("logon_3"));
					Credit_parameter.setLogon_4(rs.getInt("logon_4"));
					Credit_parameter.setLogon_5(rs.getInt("logon_5"));
					Credit_parameter.setLogon_6(rs.getInt("logon_6"));
					Credit_parameter.setLogon_7(rs.getInt("logon_7"));
					Credit_parameter.setPraise(rs.getInt("praise"));
					Credit_parameter.setReview(rs.getInt("review"));
					Credit_parameter.setAttention(rs.getInt("attention"));
					Credit_parameter.setForward(rs.getInt("forward"));
					Credit_parameter.setPublish_dynamic(rs.getInt("publish_dynamic"));
					Credit_parameter.setPraise_log(rs.getInt("praise_log"));
					Credit_parameter.setReview_log(rs.getInt("review_log"));
					Credit_parameter.setAttention_log(rs.getInt("attention_log"));
					Credit_parameter.setForward_log(rs.getInt("forward_log"));
					Credit_parameter.setMatch_level_1(rs.getInt("match_level_1"));
					Credit_parameter.setMatch_level_2(rs.getInt("match_level_2"));
					Credit_parameter.setMatch_level_3(rs.getInt("match_level_3"));
					Credit_parameter.setMatch_level_4(rs.getInt("match_level_4"));
					
					Credit_parameter.setProfession_running_result_weight(rs.getDouble("profession_running_result_weight"));
					Credit_parameter.setProfession_running_record_weight(rs.getDouble("profession_running_record_weight"));
					Credit_parameter.setProfession_basketball_steal_weight(rs.getDouble("profession_basketball_steal_weight"));
					Credit_parameter.setProfession_basketball_assist_weight(rs.getDouble("profession_basketball_assist_weight"));
					Credit_parameter.setProfession_basketball_rebound_weight(rs.getDouble("profession_basketball_rebound_weight"));
					Credit_parameter.setProfession_basketball_ponit_weight(rs.getDouble("profession_basketball_ponit_weight"));
					Credit_parameter.setProfession_basketball_result_weight(rs.getDouble("profession_basketball_result_weight"));
					Credit_parameter.setProfession_basketball_record_weight(rs.getDouble("profession_basketball_record_weight"));
					
					Credit_parameter.setProfession_swimming_result_weight(rs.getDouble("profession_swimming_result_weight"));
					Credit_parameter.setProfession_swimming_record_weight(rs.getDouble("profession_swimming_record_weight"));
					Credit_parameter.setDynamic_equilibrium(rs.getInt("dynamic_equilibrium"));
				}else{
					//do not
				}
				
				rs.close();
				ps_select.close();
				conn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		
	}
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request,response);
	}
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		String weight_selset = "select * from credit_pram";

		try {
			Connection conn = DB_connection_pool.data_pool.getConnection();
			PreparedStatement ps_select= conn.prepareStatement(weight_selset);
			ResultSet rs = ps_select.executeQuery();
			
			if(rs.next()){
				Credit_parameter.setLogon_1(rs.getInt("logon_1"));
				Credit_parameter.setLogon_2(rs.getInt("logon_2"));
				Credit_parameter.setLogon_3(rs.getInt("logon_3"));
				Credit_parameter.setLogon_4(rs.getInt("logon_4"));
				Credit_parameter.setLogon_5(rs.getInt("logon_5"));
				Credit_parameter.setLogon_6(rs.getInt("logon_6"));
				Credit_parameter.setLogon_7(rs.getInt("logon_7"));
				Credit_parameter.setPraise(rs.getInt("praise"));
				Credit_parameter.setReview(rs.getInt("review"));
				Credit_parameter.setAttention(rs.getInt("attention"));
				Credit_parameter.setForward(rs.getInt("forward"));
				Credit_parameter.setPublish_dynamic(rs.getInt("publish_dynamic"));
				Credit_parameter.setPraise_log(rs.getInt("praise_log"));
				Credit_parameter.setReview_log(rs.getInt("review_log"));
				Credit_parameter.setAttention_log(rs.getInt("attention_log"));
				Credit_parameter.setForward_log(rs.getInt("forward_log"));
				Credit_parameter.setMatch_level_1(rs.getInt("match_level_1"));
				Credit_parameter.setMatch_level_2(rs.getInt("match_level_2"));
				Credit_parameter.setMatch_level_3(rs.getInt("match_level_3"));
				Credit_parameter.setMatch_level_4(rs.getInt("match_level_4"));
			}else{
				//do not
			}
			
			rs.close();
			ps_select.close();
			conn.close();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

	}

}
